# liblinkedlist - A library of singly and doubly linked list. 

project(LIBLINKEDLIST C)
cmake_minimum_required(VERSION 2.6.3)
set ( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_admin )

# libLINKEDlist package name
set (PACKAGE "liblinkedlist")

# liblinkedDlist package version
set (LIBLINKEDLIST_VERSION_MAJOR 1)
set (LIBLINKEDLIST_VERSION_MINOR 1)
set (LIBLINKEDLIST_VERSION_MICRO 0)
set (VERSION "${LIBLINKEDLIST_VERSION_MAJOR}.${LIBLINKEDLIST_VERSION_MINOR}.${LIBLINKEDLIST_VERSION_MICRO}")
set (LIBLINKEDLIST_VERSION "\"${VERSION}\"")

set ( LIB_VERSION_CURRENT   1)
set ( LIB_VERSION_AGE       1)
set ( LIB_VERSION_REVISION  0)
set ( LIB_VERSION_INFO "${LIB_VERSION_CURRENT}.${LIB_VERSION_AGE}.${LIB_VERSION_REVISION}")

# Mandatory tool: pkg-config
find_package (PkgConfig REQUIRED)

# Default install directory names
include (DefaultDirs)

# Basic C library checks
include (CheckSTDC)
include (CheckIncludeFile)
check_include_file (string.h HAVE_STRING_H)
check_include_file (stdlib.h HAVE_STDLIB_H)
check_include_file (stdio.h HAVE_STDIO_H)

unset (LIBLINKEDLIST_CPPFLAGS CACHE)
unset (LIBLINKEDLIST_LIBS CACHE)
unset (LIST_CPPFLAGS CACHE)
unset (LIST_LIBS CACHE)

# Options for the GNU C compiler only
if (CMAKE_COMPILER_IS_GNUCC)
  if (NOT APPLE AND NOT OS2)
    set (CMAKE_EXE_LINKER_FLAGS
          "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed")
    set (CMAKE_SHARED_LINKER_FLAGS
          "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
  endif (NOT APPLE AND NOT OS2)
  set (GNUCC_WARNING_FLAGS "-Wall -W -Wpointer-arith -Wbad-function-cast -Wno-cast-qual -Wcast-align -Wstrict-prototypes -Wno-unused-parameter -Wdeclaration-after-statement")
  set (CMAKE_C_FLAGS_DEBUG "-g -fvisibility=hidden -DDEBUG ${GNUCC_WARNING_FLAGS}")
  set (CMAKE_C_FLAGS_RELEASE "-O2 -fomit-frame-pointer -funroll-all-loops -finline-functions -fvisibility=hidden -DNDEBUG ${GNUCC_WARNING_FLAGS}")
  set (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -fomit-frame-pointer -funroll-all-loops -finline-functions -fvisibility=hidden -DNDEBUG ${GNUCC_WARNING_FLAGS}")
endif (CMAKE_COMPILER_IS_GNUCC)

if ( WIN32 )
else ( WIN32 )
    find_package(Threads REQUIRED)
    set ( HAVE_LIBPTHREAD ${Threads_FOUND} )
    set ( LIBHX_LIBS "m" ${CMAKE_THREAD_LIBS_INIT})
endif ( WIN32 )

pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5)

include ( UnsetPkgConfig )

# General configuration file
configure_file (${CMAKE_SOURCE_DIR}/src/config.cmake
                 ${CMAKE_BINARY_DIR}/config.h)
add_definitions (-DHAVE_CONFIG_H)

add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(util)

enable_testing()

add_test(test_run
    util/singly_linked_list
    util/double_linked_list
    )
